﻿using System;
using System.Collections;
using System.Collections.Generic;
using System.Text;
using System.Drawing;
using System.Globalization;


namespace gChartSharp
{
    /// <summary>
    /// http://code.google.com/apis/chart/#chart_colors
    /// </summary>
    public class ColorParam : IChartParam
    {
        /// <summary>
        /// The name of the parameter
        /// </summary>
        public string Name { get { return "chco"; } }


        /// <summary>
        /// The colors
        /// </summary>
        public List<Color> Colors
        {
            get { return mColors ?? (mColors = new List<Color>()); }
            set { mColors = value; }
        }
        private List<Color> mColors;


        /// <summary>
        /// The default constructor
        /// </summary>
        public ColorParam() { }


        /// <summary>
        /// Constructor to set color list at creation
        /// </summary>
        /// <param name="colors"></param>
        public ColorParam(Color[] colors)
        {
            foreach (Color color in colors)
                this.Colors.Add(color);
        }


        /// <summary>
        /// Render the API text
        /// </summary>
        /// <returns></returns>
        public string Render()
        {
            StringBuilder sb = new StringBuilder();
            sb.Append(String.Format("&{0}=",this.Name));

            foreach (Color color in this.Colors)
            {
                sb.Append(color.ToHTML());
                sb.Append(",");
            }

            // remove last ','
            if (sb.Length > 0)
                sb.Length--;

            return sb.ToString();
        }
    }
}
